package day230320;

import java.util.Scanner;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/3/20 21:42
 * 对一句话的单词进行倒置
 */
public class Main2 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String input = in.nextLine();
        // 先整体反转一次
        String reverseString = String.valueOf(new StringBuilder(input).reverse());
        // 每个单词再反转
        String ret = reverseEachWords(reverseString.toCharArray());
        System.out.println(ret);
        in.close();
    }

    // 反转每个单词
    public static String reverseEachWords(char[] input) {
        int endIndex = 0; // 用于标记空格
        int startIndex = 0;
        while (endIndex < input.length) {
            if (input[endIndex] == ' ') {
                // 遇到空格 进行反转单词
                reverse(input, startIndex, endIndex-1);
                startIndex = endIndex + 1;
            }
            endIndex++;
        }
        // 处理最后一个单词
        reverse(input, startIndex, endIndex-1);
        return String.valueOf(input);
    }

    // 反转
    public static void reverse(char[] input, int start, int end) {
        while (start < end) {
            char temp = input[start];
            input[start] = input[end];
            input[end] = temp;
            start++;
            end--;
        }
    }
}
